import {
    http
} from '@/utils/request'


// 专题详情
export const fetchChapterDetail = async (data) => {
    let res = await http.post({
        url: '/grammar/chapterDetail',
        data
    })
    return res
}

// 上次学习

export const fetchLastChapter = async (data) => {
    let res = await http.post({
        url: '/grammar/lastChapter',
        data
    })
    return res
}
// 语法句子列表
export const fetchRatioSentence = async (data) => {
    let res = await http.post({
        url: '/grammar/ratioSentence',
        data
    })
    return res
}

// 我的课程

export const fetchMycurriculum = async (data) => {
    let res = await http.post({
        url: '/read/mycurriculum',
        data
    })
    return res
}

// 专题列表

export const fetchChapterList = async (data) => {
    let res = await http.post({
        url: '/grammar/chapter',
        data
    })
    return res
}

// 校对列表

export const fetchProofreadList = async (data) => {
    let res = await http.post({
        url: '/grammar/proofread',
        data
    })
    return res
}

// 获取结束时间

export const fetchEndTime = async (data) => {
    let res = await http.post({
        url: '/grammar/endTime',
        data
    })
    return res
}

// 校验教学码

export const validCode = async (data) => {
    let res = await http.post({
        url: '/grammar/validationCode',
        data
    })
    return res
}

// 校对提交
export const proofreadSub = async (data) => {
    let res = await http.post({
        url: '/grammar/proofreadSub',
        data
    })
    return res
}

/** 今日累计学习
 * type 0 今日， 1 累计
 * @param {*} data 
 */
export const fetchLearningToday = async (data) => {
    let res = await http.post({
        url: '/grammar/learningToday',
        data
    })
    return res
}

// 打印
export const printData = async (data) => {
    let res = await http.post({
        url: '/grammar/printData',
        data
    })
    return res
}

// 组内检测
export const fetchGroupList = async (data) => {
    let res = await http.post({
        url: '/grammar/testList',
        data
    })
    return res
}

//  提交检测
export const subTest = async (data) => {
    let res = await http.post({
        url: '/grammar/clearRedis',
        data
    })
    return res
}

// 语法句子录音提交
export const grammarSenRatioSub = async (data) => {
    let res = await http.post({
        url: '/grammar/ratioSub',
        data
    })
    return res
}

// 手动调整红黄紫格
export const fetchManual = async (data) => {
    let res = await http.post({
        url: '/grammar/manual',
        data
    })
    return res
}

// 提交红黄紫

export const manualSub = async (data) => {
    let res = await http.post({
        url: '/grammar/manualSub',
        data
    })
    return res
}

// 练一练
export const grammarTest = async (data) => {
    let res = await http.post({
        url: '/grammar/answerTest',
        data
    })
    return res
}

// 练一练提交
export const grammarTestSub = async (data) => {
    let res = await http.post({
        url: '/grammar/answerSub',
        data
    })
    return res
}

// 答题报告
export const lastAnswer = async (data) => {
    let res = await http.post({
        url: '/grammar/lastAnswer',
        data
    })
    return res
}

// 答题技巧
export const grammarExerciseSkill = async (data) => {
    let res = await http.post({
        url: '/grammar/grammarexerciseskill',
        data
    })
    return res
}

// 考点解析

export const grammarPoint = async (data) => {
    let res = await http.post({
        url: '/grammar/points',
        data
    })
    return res
}
// 查词
export const checkWord = async (data) => {
    let replaceWord = data.word.replace(/<[^>]*>/g, '').match(/(([a-z]+[\—\-\'\’]+[a-z]+)|([a-z]+))/ig) // eslint-disable-line
    const str = replaceWord ? replaceWord[0] : ''; // eslint-disable-line
    const fmdata = {
        word: str
    }
    let res = await http.post({
        url: '/read/searchword?'+ str,
        data: fmdata
    })
    return res
}

// 添加生词
export const addWord = async (data) => {
    let res = await http.post({
        url: '/read/addword',
        data
    })
    return res
}

// 填空、改错列表
export const grammarBlank = async (data) => {
    let res = await http.post({
        url: '/grammar/grammarexerciselist',
        data
    })
    return res
}

// 中断学习
// question_type 0单词,1阅读,2听说,3语法,4写作
// id 阅读与听说值是question_id 其他为课程id
export const middleStop = async (data) => {
    let res = await http.post({
        url: '/index/middlestop',
        data
    })
    return res
}

// 填空、改错详情
export const grammarDetailInfo = async (data) => {
    let res = await http.post({
        url: '/grammar/grammarexerciseinfo',
        data
    })
    if (+res.code === 1) {
        let __question_content = res.data.question_content.replace(/(\.|\'|\‘|\，|\:|\))/ig, '$1 ').replace('(', ' (') // eslint-disable-line
        res.data.question_content = __question_content
        return res
    } else {
        return res
    }
}
// 提交填空、改错
export const subGrammarDetail = async (data) => {
    let res = await http.post({
        url: '/grammar/grammarexerciseup',
        data
    })
    return res
}
// 填空改错 分析 
export const grammarDetailPort = async (data) => {
    let res = await http.post({
        url: '/grammar/grammarexercisereport',
        data
    })
    return res
}

// 填空改错打印 
export const grammarExercisePrint = async (data) => {
    let res = await http.post({
        url: '/grammar/grammarexerciseprint',
        data
    })
    return res
}
// 填空笔记提交
export const blankMarkSub = async (data) => {
    let res = await http.post({
        url: '/grammar/grammarexerciseaddmark',
        data
    })
    return res
}